﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DrawIO45.Models.Logic
{
    public class LMethodInfo
    {
        /// <summary>
        /// 函数名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// id
        /// </summary>
        public string Id { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// 全名
        /// </summary>
        public string FullName { get; set; }

        ///// <summary>
        ///// 返回类型
        ///// </summary>
        //public LClassInfo ReturnType { get; set; }

        ///// <summary>
        ///// 参数列表
        ///// </summary>
        //public List<LClassType> Parameters { get; set; }

        /// <summary>
        /// 来源
        /// </summary>
        public MethodInfo Source { get; set; }

        public string GetFormatName()
        {
            return $"+ {Name}:{LHelper.GetTypeName(Source.ReturnType)}";
        }

        public static LMethodInfo GetLMethodInfo(MethodInfo methodInfo)
        {
            if (methodInfo == null)
                return null;

            return new LMethodInfo
            {
                Name = methodInfo.Name,
                FullName = $"{methodInfo.DeclaringType.FullName}.{methodInfo.Name}",

                Source = methodInfo,
            };
        }
    }
}
